//获取应用实例
const app = getApp()
Page({
	data: {
		selectPerson:true,
		selectPerson1:true,
		firstPerson:'商户类型',
		secondPerson:'优惠券类型',
		selectArea:false,
		selectArea1:false,
		cardTicket:{}
	},
	onLoad:function(options){
		var that = this;
		//优惠券列表
		app.request('/api/Coupon/getCouponList', {}, function(res){
			if(res.code == '0'){
				//更新数据
				that.setData({
					cardTicket:res.data.data
				});
			}
		});
	},
	//点击选择类型
	clickPerson:function(){
		var selectPerson = this.data.selectPerson;
		if(selectPerson == true){
			this.setData({
				selectArea:true,
				selectPerson:false,
			})
		}else{
			this.setData({
				selectArea:false,
				selectPerson:true,
			})
		}
	},
	clickPerson1:function(){
		var selectPerson1 = this.data.selectPerson1;
		if(selectPerson1 == true){
			this.setData({
				selectArea1:true,
				selectPerson1:false,
			})
		}else{
			this.setData({
				selectArea1:false,
				selectPerson1:true,
			})
		}
	},
	//点击切换
	mySelect:function(e){
		this.setData({
			firstPerson:e.target.dataset.me,
			selectPerson:true,
			selectArea:false,
		})
		var that = this;		
		if(e.target.dataset.me == "商场"){
			var _merchant = 1;
		}
		else if(e.target.dataset.me == "商户"){
			var _merchant = 2;
		}
		if(that.data.secondPerson == "满减"){
			var _type = 1;
		}
		else if(that.data.secondPerson == "折扣"){
			var _type = 2;
		}
		else if(that.data.secondPerson == "现金"){
			var _type = 3;
		}
		//优惠券查询
		app.request('/api/Coupon/getCouponList', {type:_type,merchant:_merchant}, function(res){
			if(res.code == '0'){
				//更新数据
				that.setData({
					cardTicket:res.data.data
				});
			}
		});
	},
	mySelect1:function(e){
		this.setData({
			secondPerson:e.target.dataset.me,
			selectPerson1:true,
			selectArea1:false,
		})
		var that = this;
		if(e.target.dataset.me){
			if(that.data.firstPerson == "商场"){
				var _merchant = 1;
			} 
			else if(that.data.firstPerson == "商户"){
				var _merchant = 2;
			}
			if(e.target.dataset.me == "满减"){
				var _type = 1;
			} 
			else if(e.target.dataset.me == "折扣"){
				var _type = 2;
			} 
			else if(e.target.dataset.me == "现金"){
				var _type = 3;
			}
			//优惠券查询
			app.request('/api/Coupon/getCouponList', {type:_type,merchant:_merchant}, function(res){
				if(res.code == '0'){
					//更新数据
					that.setData({
						cardTicket:res.data.data
					});
				}
			});
		}
	},
	onShareAppMessage(res){
		return{
			title:'四海唐人街-优惠券',
			path:'/pages/discount/discount',
			imageUrl:'/images/44.jpg'
		}
	}
})